public class TabuSearch {
    private NeighborhoodSearch neighbor;
    private NeighborhoodSearch neighborhood;
    private NeighborhoodSearch[] tabu_list; //储存当前value总值最高的分配
    private int num = 0; //list现有item数
    private int value; //当前value总值最大值
    public TabuSearch() {
        neighbor = new NeighborhoodSearch();
        tabu_list = new NeighborhoodSearch[5];//5 is enough to find the global optimal solution in the local optimum
        for(int i = 0; i < tabu_list.length; i++) {
            tabu_list[i] = new NeighborhoodSearch(neighbor.getGreedy());
        }
        neighborhood = new NeighborhoodSearch(neighbor.getGreedy());
        neighborhood.circle();
        System.out.println("Neighborhood Search");
        neighborhood.Output();
        value = 0;
        Tabu_Search();
    }
    private void Tabu_Search() {
        while(num < tabu_list.length) {
            neighbor.circle();
            if(neighbor.getTotalValue() >= value) {
                tabu_list[num++] = new NeighborhoodSearch(neighbor.getGreedy());
                value = neighbor.getTotalValue();
            }
        }
    }
    public void Output() {
        int best = 0;
        int best_value = 0;
        for(int i = 0; i < tabu_list.length; i++) {
            if(tabu_list[i].getTotalValue() > best_value) {
                best_value = tabu_list[i].getTotalValue();
                best = i;
            }
        }
        tabu_list[best].Output();
    }
    public static void main(String[] args) {
        TabuSearch tabu = new TabuSearch();
        System.out.println("Tabu Search");
        tabu.Output();
    }
}
